package com.entertainment.ticketing.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;

import java.time.LocalDateTime;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "order_item",
        uniqueConstraints = {
                @UniqueConstraint(name = "uk_order_ticket", columnNames = {"order_id", "ticket_id"})
        },
        indexes = {
                @Index(name = "idx_order_id", columnList = "order_id"),
                @Index(name = "idx_ticket_id", columnList = "ticket_id")
        })
public class OrderItem {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "order_id", nullable = false,
            foreignKey = @ForeignKey(name = "fk_item_order"))
    private OrderInfo order;

    @ManyToOne(optional = false)
    @JoinColumn(name = "ticket_id", nullable = false,
        foreignKey = @ForeignKey(name = "fk_item_ticket"))
    private TicketInfo ticket;

    @Column(name = "price", nullable = false, precision = 10, scale = 2)
    private java.math.BigDecimal price;

    @CreationTimestamp
    @Column(name = "created_at", nullable = false, updatable = false)
    private LocalDateTime createdAt;
}